<?php
	if(!function_exists('bEasyResourceManager')) {
		
		function bEasyResourceManager() {
			
			$aList =debug_backtrace();
			
			$sThisFile =file_get_contents(__FILE__);
			$sThisFile =trim(preg_replace("/(.)*\?>/s", "", $sThisFile)); // untill the halt compiler offset works
			
			$xConfiguration =simplexml_load_string($sThisFile);
			if($bFromFile =isset($aList[1]['file'])) {
				
				$sFilePath =$aList[1]['file'];
				
				$sFile =file_get_contents($sFilePath);
				$sFile =trim(preg_replace("/.*\?>/s", "", $sFile)); // untill the halt compiler offset works
				
				$xFile =simplexml_load_string($sFile);
				
//--//			$a =get_declared_classes();
				
				foreach($xFile->package as $xPackage) {
					$sClassPath =(string)$xConfiguration->configration->{'auto-install'}['path'];
					$sPackageName =(string)$xPackage['name'];
					$sClassFile =realpath($sClassPath.$sPackageName.".class.inc");
					
//--//				if(!in_array($sPackageName =(string)$xPackage['name'], $a)) {
						
//--//					$sClassFile =$sClassPath.$sPackageName.".class.inc";
//--//					if(!file_exists($sClassFile)) {
							
//--//						$sClass =base64_decode((string)$xPackage);
//--//						file_put_contents($sClassFile, $sClass);
//							print_r($sPackageName." - ".$sClassFile);
//--//					}
//--//				} else {
						
						$sInstalled =file_get_contents($sClassFile);
						$a['sPackageName'] =trim(preg_replace("/.*\?>/s", "", $sInstalled)); // untill the halt compiler offset works
						$xInstalled =simplexml_load_string($a['sPackageName']);
						
						$aInstallVersion =$xInstalled->xpath("/bResourceManager/summary[@name='".$sPackageName."']/@version");
						$nInstallVersion =(double)$aInstallVersion[0];
						
						$nPackageVersion =(double)$xPackage['version'];
						
						if($nInstallVersion < $nPackageVersion) {
							
							throw new Exception("Houston We Have An Error!::Wrong Version(".$xPackage['name'].") [".$nInstallVersion."][".$nPackageVersion."]. ", 0);
						}
//--//				}
				}
			} else {
				echo "not from file.";
				// you are updating the packagemanager from the commandline??
			}
			
		}
	}
	
	bEasyResourceManager();
?>

<?php return; //__halt_compiler(); ?>
<bResourceManager>
	<configration version="1.0">
		<auto-update href="http://www.art-k-tec.com/autoupdate" />
		<auto-install path="../classes/" />
	</configration>
	<package type="class" name="bArray" version="1.0"></package>
	<package type="file" name="dock" version="1.0"><!-- this is a zipfile --></package>
	<package type="pack" name="usermanagement" version="1.0"><!-- this is a zipfile --></package>
</bResourceManager>